import { defineStore } from "pinia";
import { reactive, ref } from "vue";
import router from '@/routers/index'

/**
 * 系统相关
 */
export const useSystemStore = defineStore("system", () => {
  const menuOpen = ref(true);
  const menuSize = ref(200);
  const changeMenuType = () => {
    menuOpen.value = !menuOpen.value;
    menuSize.value = menuOpen.value ? 200 : 80;
  };

  const pageName = ref("首页");
  const setPageName = (name: string) => {
    pageName.value = name;
  };

  return { menuOpen, menuSize, pageName, changeMenuType, setPageName };
});

/**
 * 用户相关
 */
export const useUserStore = defineStore("user", () => {
  const userInfo = reactive({
    avatar: '',
    name: '王国峰',
    author: 'admin_author'
  })

  /**
   * 退出登录
   */
  const outLogin = () => {
    // 销毁信息

    // 跳转登录页面
    router.push({ name: "LoginPage" })
  }

  /**
   * 是否具备管理权限
   */
  const judeAdminUser = () => {
    return userInfo.author === ADMIN_AUTHOR
  }

  return { userInfo, outLogin, judeAdminUser }
})
